package myLogger;

import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

public class MyLoggerSetup {

    public MyLoggerSetup() {
        // Remove the default handler from the root logger
        Logger parentLogger = Logger.getLogger(""); 
        Handler[] handlers = parentLogger.getHandlers();  
        for (Handler handler : handlers) {
           parentLogger.removeHandler(handler);
        }
        // create logger fomatter
        LogFormatter formatter = new LogFormatter();
        // setup all logs that are smaller than WARNINGS to stdout
        MaxlevelStreamHandler myInfoHandler = new MaxlevelStreamHandler(System.out, formatter);
        myInfoHandler.setLevel(Level.ALL);
        myInfoHandler.setMaxlevel(Level.INFO);
        // setup all warnings to stdout & warnings and higher to stderr
        MaxlevelStreamHandler myErrHandler = new MaxlevelStreamHandler(System.err, formatter);
        myErrHandler.setLevel(Level.WARNING);
        // add output handler to logger root
        Logger.getLogger("").addHandler(myInfoHandler);
        Logger.getLogger("").addHandler(myErrHandler);
    }
    
}
